package jjoms.model.member;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import jjoms.model.item.MessageVO;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class MemberDAOImpl implements MemberDAO {
	@Resource(name = "sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;

	public MemberVO login(MemberVO vo) {
		System.out.println("DAO:" + vo.getMemberId());
		System.out.println(sqlSessionTemplate.selectOne("member.login", vo));
		return sqlSessionTemplate.selectOne("member.login", vo);
	}

	public int idcheck(String memberId) {
		return (int) sqlSessionTemplate.selectOne("member.idcheck", memberId);
	}

	public void registerMember(MemberVO vo) {
		sqlSessionTemplate.insert("member.registerMember", vo);
	}

	public MemberVO findMemberById(String memberId) {
		// System.out.println(sqlSessionTemplate.selectOne("member.findMemberById",memberId));
		return sqlSessionTemplate.selectOne("member.findMemberById", memberId);
	}

	public void updateMember(MemberVO vo) {
		sqlSessionTemplate.update("member.updateMember", vo);
	}

	public List<MemberVO> getAllMemberList() {
		return sqlSessionTemplate.selectList("member.getAllMemberList");
	}

	public void deleteMember(String memberId) {
		sqlSessionTemplate.delete("member.deleteMember", memberId);
	}

	public String findId(String memberName, String phone) {
		HashMap map = new HashMap<>();
		map.put("memberName", memberName);
		map.put("phone", phone);
		return sqlSessionTemplate.selectOne("member.findId", map);
	}

	public MemberVO findPassword(String memberId) {
		return sqlSessionTemplate.selectOne("member.findPassword", memberId);
	}

	public void updateMemberMoney(HashMap map) {
		sqlSessionTemplate.update("member.updateMemberMoney", map);
	}

	@Override
	public List<String> getAllManagerList() {
		int memberPoint = -1;
		return sqlSessionTemplate.selectList("member.getAllManagerList",
				memberPoint);
	}

	@Override
	public void updateSellAuthority(String memberId) {
		sqlSessionTemplate.update("member.updateSellAuthority", memberId);
	}

	@Override
	public void passAuthorityMember(String memberId) {
		sqlSessionTemplate.update("member.passAuthorityMember", memberId);
	}

	@Override
	public List<MessageVO> getMessageBySender(String memberId) {
		return sqlSessionTemplate.selectList("member.getMessageBySender",
				memberId);
	}

	@Override
	public List<MessageVO> getMessageByReceiver(String memberId) {
		return sqlSessionTemplate.selectList("member.getMessageByReceiver",
				memberId);
	}
	@Override
	public void updateSenderCheck(int messageNo){
		sqlSessionTemplate.update("member.updateSenderCheck",messageNo);
	}
	@Override
	public void updateReceiverCheck(int messageNo){
		sqlSessionTemplate.update("member.updateReceiverCheck",messageNo);
	}
	@Override
	public void deleteSenderReceiverCheck(int messageNo){
		sqlSessionTemplate.delete("member.deleteSenderReceiverCheck",messageNo);
	}

	//회원 등급을 받아온다.
	@Override 
	public String getGrade(String memberId) {
		System.out.println("회원등급을 받아오자" + memberId);
		return sqlSessionTemplate.selectOne("member.getGrade",memberId);
	}
}
